<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header">导入</div>
                <div class="layui-card-body" pad15>
                    <div class="layui-form layui-form-pane" lay-filter="{$lay_table}">
                        <div class="layui-form-item">
                            <label class="layui-form-label">文件名</label>
                            <div class="layui-input-block">
                                <input type="text" id="file_name" autocomplete="off" readonly placeholder="请点击上传文件按钮" class="layui-input">
                            </div>
                        </div>
                        <input type="hidden" name="file_url" value="" id="file_url">
                        <div class="layui-form-item">
                            <div class="layui-input-block">
                                <a href="{$template_file}" target="_blank">
                                    <button type="button" class="layui-btn layui-btn-normal" id="test3">下载模板</button>
                                </a>
                                <button type="button" class="layui-btn layui-btn-normal" id="upload"><i class="layui-icon"></i>上传文件</button>
                                <input type="button" lay-submit lay-filter="{$lay_btn}" value="确认提交" class="layui-btn">
                            </div>
                        </div>
                    </div>

                </div>
            </div>
        </div>
    </div>
</div>


<script>
    layui.use(['index', 'form', 'upload'], function() {
        const $ = layui.$;
        const admin = layui.admin;
        const upload = layui.upload;
        const form = layui.form;
        form.render();

        form.on('submit({$lay_btn})', function(obj) {
            var index = parent.layer.getFrameIndex(window.name);
            admin.req({
                url:  "{$url}",
                data: obj.field,
                type: 'post',
                done: function(res) {
                    layer.msg("导入成功", {
                        icon: 1
                    });
                    parent.layui.table.reload('{$last_table}'); //重载表格
                    parent.layer.close(index);
                }
            });
        });

        upload.render({
            elem: '#upload'
            ,url: "{:url('upload/file')}" //此处配置你自己的上传接口即可
            ,accept: 'file' //普通文件
            ,done: function(res){
                $('#file_url').val(res.data.path);
                $('#file_name').val(res.data.title);
            }
        });
    });
</script>
